package com.tsd.base.service.impl;

import com.tsd.base.dao.BaseFundAccountMapper;
import com.tsd.base.entity.BaseFundAccount;
import com.tsd.base.entity.BaseFundAccountExt;
import com.tsd.base.service.BaseFundAccountService;
import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：BaseFundAccount 服务实现层
 *
 * @author Hillpool
 * @date 2022/12/12 11:17:37
 */
@Service
public class BaseFundAccountServiceImpl extends BaseServiceImpl implements BaseFundAccountService {

    @Resource
    private BaseFundAccountMapper baseFundAccountMapper;

    @Override
    public BaseFundAccount getBaseFundAccountById(Long id) throws Exception {
        return baseFundAccountMapper.selectByPrimaryKey(id);
    }

    @Override
    public BaseFundAccountExt queryBySid(String sid) throws Exception {
        return baseFundAccountMapper.selectBySid(sid);
    }

    @Override
    public void deleteBaseFundAccounts(List<String> list, SysUser opUser) throws Exception {
        for (String sid : list) {
            BaseFundAccount old = baseFundAccountMapper.selectBySid(sid);
            super.checkEmpty(old, "该记录不存在");
            super.autoInjectBaseData(old, opUser, TYPE_DELETE);
            baseFundAccountMapper.updateByPrimaryKeySelective(old);
        }
    }

    @Override
    public void saveBaseFundAccount(BaseFundAccount record, SysUser opUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, this.TYPE_CREATE);
            baseFundAccountMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, this.TYPE_UPDATE);
            baseFundAccountMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<BaseFundAccountExt> findBaseFundAccounts(Map<String, Object> params, PageBean page) throws Exception {
        if (page == null) {
            baseFundAccountMapper.selectByParams(params);
        }
        return baseFundAccountMapper.selectByPage(params, page);
    }

    @Override
    public List<BaseFundAccountExt> findBaseFundAccounts(Map<String, Object> params) throws Exception {
        return baseFundAccountMapper.selectByParams(params);
    }
}